# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
##
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
__docformat__ = "restructuredtext en"
__all__ = []

from ... import formlib as layout
from ... import hint
from ... import pilelib as stack
from ...gamelib import info as gi, game
from ...packlib import info as cs
from ...piles import tarock as tstack

Wrap = stack.StackWrapper
GT, SL = gi.GT, gi.SL


class WheelOfFortune(cs.Tarock_Deck, game.Game):
    """
    Finish 1 deck on _foundation_.

    Layout
      - row [21 wheel-shape E,  offset]
      - talon [1 SE, no offset]
      - waste [1 W talon, no offset]
      - foundation [5 over 2 cols NE, no offset]

    :CVariables:
      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.WasteTalon (num_deal=2)

        Deal 2 card per waste on click. No redeals.

      _waste_ : pysollib.stack.Stack
        .. pysollib.stack.WasteStack

        Init 2 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stack.SS_Foundation

        Build up in rank by same suit. Play top. Base ace or low trump.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.tarock.ShadeSS_RowStack (max_cards=2, max_move=1,
          max_accept=1)

        Init 1 card. Build down in rank by same suit. Play top. Max 2 card.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.CautiousDefaultHint
    """
    __info__ = dict(id=157, name="Wheel of Fortune", category=cs.TYPE_TAROCK,
                    game_type=GT.ONE_DECK, decks=1, redeals=0,
                    skill_level=SL.BALANCED, version='4.00')
    __author__ = 'Markus Oberhumer'
    __version__ = 7.70

    _talon_ = Wrap(stack.WasteTalon, num_deal=2)
    _waste_ = stack.WasteStack
    _foundation_ = stack.SS_Foundation
    _row_ = Wrap(tstack.ShadeSS_RowStack, max_cards=2, max_move=1,
                 max_accept=1)
    _hint_ = hint.CautiousDefaultHint

    def _create_game(self):
        l, s = layout.Layout(self), self.s
        self.table_size = (l.XM + 23 * l.HXS, l.YM + 11 * l.HYS)
        ddx, ddy = l.XM + l.XS * 4, l.YM
        for dx, dy in ((10, 2,), (20, 5,), (30, 11,), (39, 22,), (30, 33,),
                       (20, 39,), (10, 42,), (0, 44,), (-10, 42,), (-20, 39,),
                       (-30, 33), (-40, 22,), (-30, 11,), (-20, 5,),
                       (-10, 2,), (0, 0,), (-20, 18,), (-10, 21,), (0, 22,),
                       (10, 24,), (20, 26,),):
            x, y = l.delta_coords(x=ddx, y=ddy, dx=dx, dy=dy, fx=10, fy=10)
            s['rows'].append(self._row_(x, y, game=self))
        self._set_region(s.rows, l._region(h=l.XS * 9))
        ddx, ddy = self.width - l.XS * 2, l.YM
        for (x, y), suit in zip(((0, 0,), (2, 0,), (0, 1,), (2, 1,), (1, 2,)),
                                 l.SUIT):
            x, y = l.delta_coords(x=ddx, y=ddy, dx=0, dy=0, fx=2)
            s['foundations'].append(self._foundation_(x, y, game=self,
                                                   suit=suit))
        x, y = self.width - l.XS, self.height - 3 * l.HYS
        s['talon'] = self._talon_(x, y, game=self)
        l.set_ncards_text(s['talon'], "n")
        x -= l.XS
        s['wastes'].append(self._waste_(x, y, game=self))
        l.set_ncards_text(s['wastes'][-1], "n")
        l.defaultStackGroups()
        return l

    def _start(self):
        self._play_sound('deal')
        self.s['talon'].dealRow(rows=self.s.rows[-5:])
        self.s['talon'].dealRow(rows=self.s.rows[4:-5])
        self.s['talon'].dealRow(rows=self.s.rows[:4])
        self.s['talon'].deal_cards()


PROVIDES = [WheelOfFortune]